package com.saudidentalapp;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.saudiapp.lazylist.ImageLoader;
import com.saudidentalapp.datamodels.Committee;

public class PosterAdapter extends ArrayAdapter<Committee>
{

	Context context;
    int layoutResourceId;    
    ArrayList<Committee>data;
    public ImageLoader imageLoader; 
    private static LayoutInflater inflater=null;
	public PosterAdapter(Context context, int resource, List<Committee> objects) 
	{
		super(context, resource, objects);
		 this.layoutResourceId = resource;
	        this.context = context;
	        this.data = (ArrayList<Committee>) objects;
	        inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	        imageLoader=new ImageLoader(context.getApplicationContext());
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) 
	{
		View row = convertView;
		Holder holder = null;
       
        if(row == null)
        {
            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);
           
            holder = new Holder();
            holder.imgThumb = (ImageView)row.findViewById(R.id.ximgThumb);
            holder.txtTitle = (TextView)row.findViewById(R.id.xtxtPosterTitle);
            holder.txtDescription = (TextView)row.findViewById(R.id.xtxtPosterDescription);
           
           
            row.setTag(holder);
        }
        else
        {
            holder = (Holder)row.getTag();
        }
       
        Committee committee = getItem(position);
        imageLoader.DisplayImage(committee.getThumbImage(), holder.imgThumb);
        holder.txtTitle.setText(committee.getName());
        holder.txtDescription.setText(committee.getDesignation());
       
        return row;
    }
   
    static class Holder
    {     
    	ImageView imgThumb;   
        TextView txtTitle;   
        TextView txtDescription;   
        
    }
}

